#include "media/logic/MediaLogicRT.h"
#include <qtextcodec.h>

MediaLogicCT::MediaLogicCT(QMap<QString, QMap<QString, QString>> &RGLRLSMAP,
                           QSqlDatabase *DB,
                           QMap<QString, QString> &QSSMAP)
    : MediaLogicTT(RGLRLSMAP, DB, QSSMAP){
}

void MediaLogicCT::tab_attribute_max(int maxrow){
    diary("datac " + QString::number(maxrow), Diary::Warning)
    if (maxrow)
    {
        RT_mediaTabWidget->setColumnWidth(0, RT_mediaTabWidget->font().pointSize() * 4);
        RT_mediaTabWidget->setColumnWidth(1, TABLE_COLUMN2W); //在此设置第二列列宽，否则第二列列宽初始化已完成设置，则在第一列设置列宽时，会对第二列列宽造成缩大或者缩小的影响
        RT_mediaTabWidget->setRowCount(maxrow);
        for(int row = 0; row < maxrow; row++) RT_mediaTabWidget->setRowHeight(row, TAB_ROW_HEIGHT); //设置行高，为滚动条提供精度
        RT_mediaTabWidget->d_avgheight(TAB_ROW_HEIGHT);
    }
}

void MediaLogicCT::tab_viewlayout_init(int row, QString name, QString artist, QString suffix, QString bitrate, QString size, QString duration, QString cover){
    QSize hintsize(66, 66); //qDebug() << row <<  name;
    if (cover.isEmpty()) cover.append(":/PIXMAP/bench/cover.jpg");
    if (RT_mediaTabWidget->item(row, 0))
    {
        if (impact_int[cover] != Extend::g_pix_fl(cover, QSize(30,30)))
        {
            QWidget *cellwidget = RT_mediaTabWidget->cellWidget(row, 1);
            if (cellwidget)
            {
                Nwidget *coverwin = static_cast<Nwidget*>(cellwidget);
                coverwin->doconfigur_pixmap(cover, hintsize, false, 6);
                impact_int[cover] = Extend::g_pix_fl(cover, QSize(30,30));
            }
        }
    }
    else
    {
        QString nametstring = name + "\n\n" + artist + " # " + suffix;
        QString infostring = bitrate + "  " + size + "  " + duration;
        QString objname = QString::number(row + 1);
        Nwidget *mdrs_cover = new Nwidget();
        mdrs_cover->setFixedSize(80,80);
        mdrs_cover->doconfigur_pixmap(cover, hintsize, false, 6);
        QTableWidgetItem *item_bsifdesc = new QTableWidgetItem(objname);
        QTableWidgetItem *item_bsifcover = new QTableWidgetItem();
        QTableWidgetItem *item_bsifnairt = new QTableWidgetItem(nametstring);
        QTableWidgetItem *item_scif = new QTableWidgetItem(infostring);

        item_bsifdesc->setTextAlignment(Qt::AlignCenter);
        item_bsifcover->setTextAlignment(Qt::AlignCenter);
        item_bsifnairt->setTextAlignment(Qt::AlignVCenter | Qt::AlignLeft);
        item_scif->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);

        RT_mediaTabWidget->setItem(row, 0, item_bsifdesc);
        RT_mediaTabWidget->setItem(row, 1, item_bsifcover);
        RT_mediaTabWidget->setCellWidget(row, 1, mdrs_cover);
        RT_mediaTabWidget->setItem(row, 2, item_bsifnairt);
        RT_mediaTabWidget->setItem(row, 3, item_scif);

        if ((!impact_swtc["tab-column-specing-adjusted"] && !infostring.simplified().isEmpty()) ||
              impact_str["tab-column-adjusted-last"].size() < infostring.size())
    {
        int first_width = RT_mediaTabWidget->columnWidth(0);
        int second_width = RT_mediaTabWidget->columnWidth(1);
        int lastcl_width = QFontMetrics(RT_mediaTabWidget->font()).horizontalAdvance(infostring) +
                           RT_mediaTabWidget->vscroll->width() * 2;
        RT_mediaTabWidget->setColumnWidth(3, lastcl_width);
        RT_mediaTabWidget->setColumnWidth(2,
                                          RT_mediaTabWidget->width() -
                                          first_width -
                                          second_width -
                                          lastcl_width);
        impact_swtc["tab-column-specing-adjusted"] = true;
        impact_str["tab-column-adjusted-last"] = infostring;
    }
    }
}

void MediaLogicCT::tab_double_change(QModelIndex modelindex){
    impact_int["mdrs-indexof"] = modelindex.row();
    impact_swtc["mdplr-current-state"] = true;
    emit sg_standar_amend(false);
}

void MediaLogicCT::tab_cells_change(int row){
    impact_int["mdrs-indexof"] = row;
    RT_mediaTabWidget->selectRow(row);
}

void MediaLogicCT::tab_unexpeced_select(int min, int max){
    impact_stint["tab-unexpected-selection"] = {min, max};
    if (abs(max - min) >= 20)
    {
        setEnabled(false);
        QPoint pos = mapToGlobal(RT_mainWidget->pos());
        QSize size = RT_mainWidget->size();
        WaitTimer->d_file(":/PIXMAP/bench/waiting-life.gif");
        WaitTimer->setVisible(true);
        WaitTimer->d_centra(QRect(pos.x(), pos.y(), size.width(), size.height()));
        WaitTimer->d_config(WaitaMinit::reset);
    }
    if (min > max)
    {
        tab_variant_scroll(max, min);
    }
    else
    {
        tab_variant_scroll(min, max);
    }
}

void MediaLogicCT::tab_secload_finish(){
    QList<qint64> its = impact_stint["tab-unexpected-selection"];
    if (its.size() >= 2)
    {
        int min = its.first();
        int max = its.last();
        RT_mediaTabWidget->setSelectionMode(QAbstractItemView::MultiSelection);
        if (min < max)
        {
            RT_mediaTabWidget->selects(min, max);
        }
        else
        {
            RT_mediaTabWidget->selects(max, min);
        }
        impact_stint["tab-unexpected-selection"].clear();
        RT_mediaTabWidget->setSelectionMode(QAbstractItemView::SingleSelection);
        RT_mediaTabWidget->vscroll->setValue((double)max / RT_mediaTabWidget->rowCount() * 100, false);
        WaitTimer->d_config(WaitaMinit::pause);
        WaitTimer->setVisible(false);
        setEnabled(true);
    }
}

void MediaLogicCT::tab_variant_scroll(int range_min, int range_max){
    HpforTabLoader->setInfo(impact_ststr, range_min, range_max);
    connect(&TAB_DLLD_QTIER, &QTimer::timeout, this, [&]()
    {
        if (impact_int["delay-tabdata-loader-wheelc"] > 2)
        {
            impact_int["delay-tabdata-loader-wheelc"] = 0;
        }
        else
        {
            // is over or from begin to end never runner
            if (HpforTabLoader->isFinished() || !HpforTabLoader->isRunning())
            {
                HpforTabLoader->start();
                TAB_DLLD_QTIER.stop();
            }
        }
    });
    if (HpforTabLoader->isRunning())
    {
        impact_thread[ThreadPoint::MULTI_TABUPDATE] = NT::THREAD_TERMINATED;
    }
    else
    {
        impact_thread[ThreadPoint::MULTI_TABUPDATE] = NT::THREAD_RECOVER;
        TAB_DLLD_QTIER.start();
    }
    impact_int["delay-tabdata-loader-wheelc"] += 1;
}

void MediaLogicCT::tab_resource_update(){
    impact_ststr["mdrs-local-folders"].swap(impact_ststr["anysql-allpath"]);
    BoilPool->run(ThreadPoint::MULTI_ADDTION);
}

void MediaLogicCT::tab_find(QListWidgetItem *item){
    if (item)
    {
        QString current_text = item->text();
        double indexof = impact_ststr["reserve-duty-name"].indexOf(current_text);
        RT_mediaTabWidget->vscroll->setValue(indexof / RT_mediaTabWidget->rowCount() * 100);
        impact_int["tab-find-index"] = indexof;
        QTimer::singleShot(1000, this, [&](){RT_mediaTabWidget->selectRow(impact_int["tab-find-index"]);});
    }
    else
    {
        QString keyword = RTP_TbmatchComboBox->g_linedit()->text();
        if (!keyword.isEmpty())
        {
            QStringList matchdata = impact_ststr["reserve-duty-name"].filter(keyword);
            RTP_TbmatchComboBox->g_stall()->clear();
            if (!matchdata.isEmpty())
            {
                RTP_TbmatchComboBox->g_stall()->addItems(matchdata);
                RTP_TbmatchComboBox->ico_r_keep();
            }
        }
    }
}

void MediaLogicCT::funcdr_relock(NT::CST_BRIGHT_SPOT lock_type){
    switch (lock_type)
    {
        case NT::CUT_LOCALRSLOCK:
            LF_localMeidaLabel->doconfigur_lock();
            LF_nearMeidaLabel->doconfigur_unlock();
            LF_recordLabel->doconfigur_unlock();
            Favora_ListWidget->unselected();
            impact_str["mdrs-owner"] = LOCAL_OWNER;
            RT_sliderShow->setCurrentWidget(RT_tabWidget);
            abstract_reserve_loader();
            break;
        case NT::CUT_NEARRSLOCK:
            LF_localMeidaLabel->doconfigur_unlock();
            LF_nearMeidaLabel->doconfigur_lock();
            LF_recordLabel->doconfigur_unlock();
            Favora_ListWidget->unselected();
            impact_str["mdrs-owner"] = LOCAL_OWNER;
            RT_sliderShow->setCurrentWidget(RT_tabWidget);
            abstract_reserve_loader("julianday(strftime('%Y-%m-%d %H:%M:%S', 'now', 'localtime'))"
                                    " - "
                                    "julianday(strftime('%Y-%m-%d %H:%M:%S', nrply_time)) < "
                                     +
                                    QString::number(NEARPL_STALE_DATED));
            break;
        case NT::CUT_RECORDLOCK:
            LF_localMeidaLabel->doconfigur_unlock();
            LF_nearMeidaLabel->doconfigur_unlock();
            LF_recordLabel->doconfigur_lock();
            Favora_ListWidget->unselected();
            break;
        case NT::CUT_FAVORARSLOCK:
            LF_localMeidaLabel->doconfigur_unlock();
            LF_nearMeidaLabel->doconfigur_unlock();
            LF_recordLabel->doconfigur_unlock();
            RT_sliderShow->setCurrentWidget(RT_tabWidget);
            break;
        default:
            LF_localMeidaLabel->doconfigur_unlock();
            LF_nearMeidaLabel->doconfigur_unlock();
            LF_recordLabel->doconfigur_unlock();
            Favora_ListWidget->unselected();
    }
}

void MediaLogicCT::rtp_menu_trigger(QAction *action){
    if (action == add_file)
    {
        dialog_rsmatching(0);
    }

    else if (action == add_folder)
    {
        dialog_rsmatching(1);
    }

    else if (action == batch_media)
    {
        RT_mediaTabWidget->setSelectionMode(QAbstractItemView::ContiguousSelection);
    }

    else if (action == remove_overall)
    {
        impact_int["mtrs-remove-way"] = 0;
        QList<int> rows = RT_mediaTabWidget->prossRows();
        for(int i : rows) impact_stint["maint-mark-selects"].append(i);
        BoilPool->run(ThreadPoint::MULTI_REMOVE);
    }

    else if (action == remove_onlysql)
    {
        impact_int["mtrs-remove-way"] = 1;
        QList<int> rows = RT_mediaTabWidget->prossRows();
        for(int i : rows) impact_stint["maint-mark-selects"].append(i);
        BoilPool->run(ThreadPoint::MULTI_REMOVE);
    }

    else if (add_slist->actions().contains(action))
    {
        int favora_index = UserDataCore.USER_FAVOR_NS.indexOf(action->text());
        QString favora_lock = UserDataCore.USER_FAVOR_LKS[favora_index];
        foreach(qint64 indexof, RT_mediaTabWidget->prossRows(true))
        {
            QString mediaowner = impact_ststr["reserve-duty-owner"][indexof];
            QString medianame = impact_ststr["reserve-duty-name"][indexof];
            QStringList owners = mediaowner.split("&&");
            owners.append(favora_lock);
            owners.removeDuplicates();
            QString mdrsupd_sqlchar = QString("UPDATE media_datum SET owner='%1' WHERE mdrs_name='%2';").arg(owners.join("&&"), medianame);
            if (!Query->exec(mdrsupd_sqlchar))
            {
                diary("favora item update fail: " + Query->lastError().text(), Diary::Error)
            }
        }
    }
}

void MediaLogicCT::dialog_rsmatching(int type){
    if (type == 0 ){
        QString FilterQuestion = QString("media (*.%1)").arg(impact_ststr["fm-ovall"].join(" *."));
        QStringList Files = QFileDialog::getOpenFileNames(this,
                                                          "add file",
                                                          impact_str["mdrs-follow-directory"],
                                                          FilterQuestion);
        if (!Files.isEmpty()){
            QString HintStr;
            if (Files.size() <= 5){
                HintStr = Files.join("\n");
            } else {
                HintStr = Files.mid(0, 5).join("\n");
                HintStr.append("...");
            }
            MessageBoxQ *fileBox = new MessageBoxQ(this,
                                                 {"add the path", "ignore"},
                                                 MessageBoxQ::MSG_Question,
                                                 "add file",
                                                 QString("file verify:\n%1").arg(HintStr));
            impact_ststr["mdrs-local-files"] = Files;
            connect(fileBox, &MessageBoxQ::checkEvent, this, &MediaLogicCT::dialog_dispose_file);
        }
    } else {

        QString Folder = QFileDialog::getExistingDirectory(this,
                                                           "add folder",
                                                           impact_str["mdrs-follow-directory"],
                                                           QFileDialog::ShowDirsOnly);
        if (!Folder.isEmpty()){
            MessageBoxQ *dirBox = new MessageBoxQ(this,
                                                  {"add the path", "ignore"},
                                                  MessageBoxQ::MSG_Question,
                                                  "add folder",
                                                  QString("File Verify:\n%1").arg(Folder));
            impact_ststr["mdrs-local-folders"] = {Folder};
            QObject::connect(dirBox, &MessageBoxQ::checkEvent, this, &MediaLogicCT::dialog_dispose_folder);
        }
    }
}

void MediaLogicCT::dialog_dispose_folder(QAbstractButton *but){
    if (but->text() != "ignore")
    {
        if (impact_str["mdrs-follow-directory"] == "follow")
        {
            impact_str["mdrs-follow-directory"] = impact_ststr["mdrs-local-folders"].last();
        }
        BoilPool->run(ThreadPoint::MULTI_ADDTION);
    }
}

void MediaLogicCT::dialog_dispose_file(QAbstractButton *but){
    if (but->text() != "ignore" && !impact_ststr["mdrs-local-files"].isEmpty())
    {
        if (impact_str["mdrs-follow-directory"] == "follow")
        {
            impact_str["mdrs-follow-directory"] = QFileInfo(impact_ststr["mdrs-local-files"].last()).canonicalPath();
        }
        BoilPool->run(ThreadPoint::MULTI_ADDTION);
    }
}

void MediaLogicCT::favora_loader(QString text, bool isreadonly, QString ico){
    Nwidget *temporary = new Nwidget();
    temporary->setAttribute(Qt::WA_DeleteOnClose);
    QHBoxLayout *temHbox = new QHBoxLayout(temporary);
    NinsipidView * favora_logo = new NinsipidView(temporary);
    NLineEdit *lineEdit = new NLineEdit(temporary);
    NinsipidView *favora_rename = new NinsipidView(temporary);
    favora_logo->setFixedHeight(23);
    favora_logo->doconfigur_adjustedwidth(true);
    (ico.isEmpty() || ico == "NULL") ? favora_logo->doconfigur_pixmap(":/PIXMAP/bench/private_dvd.png") : favora_logo->doconfigur_pixmap(ico);
    favora_rename->setFixedHeight(23);
    favora_rename->doconfigur_adjustedwidth(true);
    favora_rename->doconfigur_brighttype(NT::DRAWTYPE_ROUND);
    favora_rename->doconfigur_imgsetting(NT::DRAWTYPE_RECT, NT::PIXLOAD_IGNORERATIO_LOWER, 3);
    favora_rename->doconfigur_backcolorgroup({{MSEVKEY.WIN_ENTER, QColor(230,230,230,180)}});
    favora_rename->doconfigur_autoswitch_pixpre(":/PIXMAP/bench/private-edit.png", ":/PIXMAP/bench/private-edit-finish.png");
    lineEdit->setStyleSheet("QLineEdit{background:transparent;"
                            "border:0px;"
                            "color:rgba(89,89,89,200);"
                            "font-family: KaiTi_GB2312;"
                            "font:12px;}");
    lineEdit->setReadOnly(isreadonly);
    lineEdit->setText(text);
    temHbox->addWidget(favora_logo);
    temHbox->addWidget(lineEdit);
    temHbox->addWidget(favora_rename);
    temHbox->setAlignment(Qt::AlignVCenter);
    temHbox->setContentsMargins(3,0,5,0);
    temHbox->setSpacing(0);
    QListWidgetItem *temporary_item = new QListWidgetItem();
    QString objectname = QString::number(Favora_ListWidget->count());
    Favora_ListWidget->addItem(temporary_item);
    Favora_ListWidget->setItemWidget(temporary_item, temporary);
    temporary->setObjectName(objectname);
    lineEdit->setObjectName(objectname);
    favora_logo->setObjectName(FAVORA_ITEM_LOGO_FLAG + objectname);
    favora_rename->setObjectName(FAVORA_ITEM_RENAME_FLAG + objectname);
    connect(temporary, &Nwidget::msnm_rls, this, &MediaLogicCT::favora_elect);
    connect(lineEdit, &NLineEdit::msnm_rls, this, &MediaLogicCT::favora_elect);
    connect(favora_logo, &NinsipidView::msnm_rls, this, &MediaLogicCT::favora_elect);
    connect(favora_rename, &NinsipidView::msnm_pre, this, &MediaLogicCT::favora_elect);
    connect(favora_rename, &NinsipidView::msev_swtc_pre, this, &MediaLogicCT::favora_variant);
}

void MediaLogicCT::favora_elect(QString name){
    if (!definfc.isInt(name)) name.remove(FAVORA_ITEM_LOGO_FLAG).remove(FAVORA_ITEM_RENAME_FLAG);
    int indexof = name.toInt();
    QListWidgetItem *expectitem = Favora_ListWidget->item(indexof);
    if (expectitem)
    {
        NLineEdit *expectitem_edimdl = Favora_ListWidget->itemWidget(expectitem)->findChild<NLineEdit*>(QString::number(indexof));
        if (expectitem_edimdl)
        {
            if (!expectitem_edimdl->text().isEmpty() && indexof < UserDataCore.USER_FAVOR_LKS.length())
            {
                impact_str["favora-text"] = expectitem_edimdl->text();
                impact_str["mdrs-owner"] = UserDataCore.USER_FAVOR_LKS[indexof];
                abstract_reserve_loader();
                funcdr_relock(NT::CUT_FAVORARSLOCK);
            }
        }
        //不需要经过文本框判断才赋值，因为当添加item时，item文本框初始为空的，无法通过条件判断，因此 favora-row 得不到更新，导致添加流程异常
        impact_int["favora-row"] = indexof;
        expectitem->setSelected(true);
    }
    else
    {
        impact_str["favora-text"].clear();
        impact_int["favora-row"] = -1;
    }
}

void MediaLogicCT::favora_variant(QVariant data){
    QListWidgetItem *favora_apresentitem = Favora_ListWidget->item(impact_int["favora-row"]);
    if (data.metaType().id() == QMetaType::Int && data.toInt() == 0 && !Favora_ListWidget->selectedItems().isEmpty())
    {
        diary("favora remove now", Diary::Debug)
        if (favora_apresentitem)
        {
            QWidget *itemwidget = Favora_ListWidget->itemWidget(favora_apresentitem);
            if (itemwidget)
            {
                QString favora_lock = UserDataCore.USER_FAVOR_LKS[UserDataCore.USER_FAVOR_NS.indexOf(impact_str["favora-text"])];
                QString favoradel_sqlchar = QString("DELETE FROM user_favora_datum WHERE ac_mdfvr='%1';").arg(impact_str["favora-text"]);
                if (Query->exec(favoradel_sqlchar))
                {
                    Favora_ListWidget->del(impact_int["favora-row"]);
                    diary(QString("favora item [%1] delete success").arg(impact_str["favora-text"]), Diary::Debug)
                    QMap<QString, QList<QString>> SqlMediaInfo = definfc.SuperQuery(DATABASE, "media_datum", QString("owner like '%%1%'").arg(favora_lock));
                    QList<QString> mdrs_names = SqlMediaInfo["mdrs_name"];
                    QList<QString> mdrs_owners = SqlMediaInfo["owner"];
                    for(int index = 0; index < mdrs_names.size(); index++)
                    {
                        QString name = mdrs_names[index];
                        QStringList owners = mdrs_owners[index].split("&&");
                        owners.removeAll(favora_lock);
                        QString mdrsupd_sqlchar = QString("UPDATE media_datum SET owner='%1' WHERE mdrs_name='%2';").arg(owners.join("&&"), name);
                        if (!Query->exec(mdrsupd_sqlchar)) diary("data sql update error: " + Query->lastError().text(), Diary::Error)
                    }
                } else diary("favora delete error: " + Query->lastError().text(), Diary::Error)
            }
            Favora_ListWidget->desc();
        }
    }

    else if (data.metaType().id() == QMetaType::Bool) //favora history ready
    {
        QString favora_objectname = QString::number(impact_int["favora-row"]);
        NLineEdit *expectitem_edimdl = Favora_ListWidget->itemWidget(favora_apresentitem)->findChild<NLineEdit*>(favora_objectname);
        diary("favora editing index: " + favora_objectname + " | " + QString::number(data.toBool()), Diary::Debug)
        if (expectitem_edimdl)
        {
            QString favora_text = expectitem_edimdl->text();
            if (data.toBool()) // editing
            {
                expectitem_edimdl->setReadOnly(false);
                expectitem_edimdl->setFocus();
                diary("favora editing state relieve", Diary::Debug)
            }
            else // edited
            {
                if (!expectitem_edimdl->text().isEmpty()) // nothing action because this edit module text is empty
                {
                    QString auld_id = NULL;
                    if (impact_int["favora-row"] < UserDataCore.USER_FAVOR_NS.size()) auld_id = UserDataCore.USER_FAVOR_NS[impact_int["favora-row"]];
                    if (UserDataCore.USER_FAVOR_NS.contains(auld_id) && impact_swtc["user-accept-might"])
                    {
                        QString favoraupd_sqlchar = QString("UPDATE user_favora_datum SET ac_mdfvr='%1' WHERE ac_mdfvr='%2';").arg(favora_text, auld_id);
                        if (Query->exec(favoraupd_sqlchar))
                        {
                            foreach(QAction *action, add_slist->actions())
                            {
                                if (action)
                                {
                                    if (action->text() == auld_id)
                                    {
                                        action->setText(favora_text);
                                        break;
                                    }
                                }
                            }

                            diary("favora update success", Diary::Debug)
                        } else diary("favora addtion error: " + Query->lastError().text(), Diary::Error)
                    }
                    else if (UserDataCore.USER_FAVOR_NS.contains(favora_text))
                   {
                        MessageBoxQ *hintMessage = new MessageBoxQ(this,
                                                                   {"i got it"},
                                                                   MessageBoxQ::MSG_Question,
                                                                   "Question",
                                                                   "name non-repeatable");
                        connect(hintMessage, &MessageBoxQ::checkEvent, this, [this](){
                                favora_variant(true);
                                QListWidgetItem *favora_curitem = Favora_ListWidget->item(impact_int["favora-row"]);
                                if (favora_curitem)
                                {
                                    NinsipidView *renamemdl = Favora_ListWidget->itemWidget(favora_curitem)->findChild<NinsipidView*>
                                                             (FAVORA_ITEM_RENAME_FLAG + QString::number(Favora_ListWidget->currentRow()));
                                    if (renamemdl)
                                    {
                                        renamemdl->doconfigur_autoswitch_pixswap(false); // only switch ico
                                    }
                                }
                            }
                        );
                    }
                    else
                    {
                        if (favora_text.isEmpty())
                        {
                            Favora_ListWidget->del(impact_int["favora-row"]);
                            diary("favora invalid item delete success", Diary::Debug)
                        }
                        else
                        {
                            if (impact_swtc["user-accept-might"])
                            {
                                QTextCodec *textcodec = QTextCodec::codecForName("utf-8");
                                QByteArray byte84 = textcodec->fromUnicode(favora_text).toBase64();
                                QByteArray md5code = QCryptographicHash::hash(byte84, QCryptographicHash::Md5);
                                QList<QString> keys({"ac_id", "ac_mdfvr", "coverp", "lock"});
                                QList<QString> values({impact_str["ac-accept-name"], favora_text, "NULL", md5code});
                                QString favoraadd_sqlchar = QString("INSERT INTO user_favora_datum%1 VALUES%2;").arg(definfc.c_tuple(keys), definfc.c_tuple(values));
                                if (Query->exec(favoraadd_sqlchar))
                                {
                                    add_slist->addAction(new QAction(QIcon(":/PIXMAP/bench/private_dvd.png"), favora_text));
                                    diary("favora addtion success", Diary::Debug)
                                }
                                else
                                {
                                    diary("favora addtion error: " + Query->lastError().text(), Diary::Error)
                                }
                            }
                        }
                    }
                    expectitem_edimdl->setReadOnly(true);
                }
                diary("favora editing info save", Diary::Debug)
            }
        }
    }

    else if (data.metaType().id() == QMetaType::Int && data.toInt() == 2) //favora item addtion
    {
        diary("favora addtion now", Diary::Debug)
        bool readOnly = true;
        int lastindex = Favora_ListWidget->minor();
        QListWidgetItem *favora_curitem = Favora_ListWidget->item(lastindex);
        if (favora_curitem)
        {
            NLineEdit *item_edit = Favora_ListWidget->itemWidget(favora_curitem)->findChild<NLineEdit*>(QString::number(lastindex));
            if (item_edit && !item_edit->isReadOnly()) // avoid multi data in edit state
            {
                readOnly = false;
            }
        }
        if (readOnly)
        {
            favora_loader();
            int lastindex = Favora_ListWidget->minor(); // get index in item addtion after
            QString favora_objectname = QString::number(lastindex);
            favora_elect(favora_objectname); // be set constistency to ready config new item
            QListWidgetItem *favora_curitem = Favora_ListWidget->item(lastindex);
            if (favora_curitem)
            {
                NinsipidView *renamemdl = Favora_ListWidget->itemWidget(favora_curitem)->findChild<NinsipidView*>(FAVORA_ITEM_RENAME_FLAG + favora_objectname);
                if (renamemdl)
                {
                    renamemdl->doconfigur_autoswitch_pixswap(false);// only switch ico
                    favora_variant(true);
                    diary("rs addtion prepare", Diary::Debug)
                } else diary("renamemdl mdl not found ", Diary::Error)
            } else diary("favora item losing, index: " + QString::number(lastindex), Diary::Error)
        }
    }
    QMap<QString, QList<QString>> userfavora_info = definfc.SuperQuery(DATABASE, "user_favora_datum", {"ac_id"});
    user_template(userfavora_info, UserDataCore);
}
